
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <title>commitAllLifecycle · React源码解析</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.0">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-api/theme-api.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

         
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="host-effects/CommitDeletion.html" />
    

<script
  async
  src="https://www.googletagmanager.com/gtag/js?id=UA-49483742-5"
></script>
<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('js', new Date())

  gtag('config', 'UA-49483742-5')
</script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../api/react.html">
            
                <a href="../api/react.html">
            
                    
                    React API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../api/react-element.html">
            
                <a href="../api/react-element.html">
            
                    
                    ReactElement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../api/react-children.html">
            
                <a href="../api/react-children.html">
            
                    
                    React Children
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../api/react-structure.html">
            
                <a href="../api/react-structure.html">
            
                    
                    React 中的数据结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    创建更新
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../update/react-dom-render.html">
            
                <a href="../update/react-dom-render.html">
            
                    
                    ReactDOM.render
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../update/set-state.html">
            
                <a href="../update/set-state.html">
            
                    
                    setState & forceUpdate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../update/expiration-time.html">
            
                <a href="../update/expiration-time.html">
            
                    
                    expirationTime 计算
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    任务调度
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../flow/scheduler-global.html">
            
                <a href="../flow/scheduler-global.html">
            
                    
                    全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../flow/schedule-work.html">
            
                <a href="../flow/schedule-work.html">
            
                    
                    scheduleWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../flow/scheduler-pkg.html">
            
                <a href="../flow/scheduler-pkg.html">
            
                    
                    react-scheduler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../flow/perform-work.html">
            
                <a href="../flow/perform-work.html">
            
                    
                    performWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../flow/perform-unit-of-work.html">
            
                <a href="../flow/perform-unit-of-work.html">
            
                    
                    performUnitOfWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../flow/render-root.html">
            
                <a href="../flow/render-root.html">
            
                    
                    renderRoot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../flow/render-root/throw-exception.html">
            
                <a href="../flow/render-root/throw-exception.html">
            
                    
                    throwException
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../flow/begin-work.html">
            
                <a href="../flow/begin-work.html">
            
                    
                    beginWork
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.7.1" data-path="../flow/begin-work/mount-indeterminate-component.html">
            
                <a href="../flow/begin-work/mount-indeterminate-component.html">
            
                    
                    mountIndeterminateComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.2" data-path="../flow/begin-work/mount-lazy-component.html">
            
                <a href="../flow/begin-work/mount-lazy-component.html">
            
                    
                    mountLazyComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.3" data-path="../flow/begin-work/update-functional-component.html">
            
                <a href="../flow/begin-work/update-functional-component.html">
            
                    
                    updateFunctionalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.4" data-path="../flow/begin-work/update-class-component.html">
            
                <a href="../flow/begin-work/update-class-component.html">
            
                    
                    updateClassComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.5" data-path="../flow/begin-work/update-host-root.html">
            
                <a href="../flow/begin-work/update-host-root.html">
            
                    
                    updateHostRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.6" data-path="../flow/begin-work/update-host-component.html">
            
                <a href="../flow/begin-work/update-host-component.html">
            
                    
                    updateHostComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.7" data-path="../flow/begin-work/update-host-text.html">
            
                <a href="../flow/begin-work/update-host-text.html">
            
                    
                    updateHostText
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.8" data-path="../feature/Suspense-component.md">
            
                <span>
            
                    
                    updateSuspenseComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.9" data-path="../flow/begin-work/update-portal-component.html">
            
                <a href="../flow/begin-work/update-portal-component.html">
            
                    
                    updatePortalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.10" data-path="../flow/begin-work/update-forward-ref.html">
            
                <a href="../flow/begin-work/update-forward-ref.html">
            
                    
                    updateForwardRef
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.11" data-path="../flow/begin-work/update-fragment.html">
            
                <a href="../flow/begin-work/update-fragment.html">
            
                    
                    updateFragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.12" data-path="../flow/begin-work/update-mode.html">
            
                <a href="../flow/begin-work/update-mode.html">
            
                    
                    updateMode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.13" data-path="../flow/begin-work/update-profiler.html">
            
                <a href="../flow/begin-work/update-profiler.html">
            
                    
                    updateProfiler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.14" data-path="../flow/begin-work/update-context-provider.html">
            
                <a href="../flow/begin-work/update-context-provider.html">
            
                    
                    updateContextProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.15" data-path="../flow/begin-work/update-context-consumer.html">
            
                <a href="../flow/begin-work/update-context-consumer.html">
            
                    
                    updateContextConsumer
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../flow/reconcile-children.html">
            
                <a href="../flow/reconcile-children.html">
            
                    
                    reconcileChildren
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.8.1" data-path="../flow/reconcile-children/single.html">
            
                <a href="../flow/reconcile-children/single.html">
            
                    
                    调和单个节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8.2" data-path="../flow/reconcile-children/array.html">
            
                <a href="../flow/reconcile-children/array.html">
            
                    
                    调和列表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    commit 阶段
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="commit-root.html">
            
                <a href="commit-root.html">
            
                    
                    commitRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="invokeGuardedCallback.html">
            
                <a href="invokeGuardedCallback.html">
            
                    
                    invokeGuardedCallback
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="commitBeforeMutationLifecycles.html">
            
                <a href="commitBeforeMutationLifecycles.html">
            
                    
                    commitBeforeMutationLifecycles
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="commit-all-host-effects.html">
            
                <a href="commit-all-host-effects.html">
            
                    
                    commitAllHostEffects
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.4.1" data-path="host-effects/CommitPlacement.html">
            
                <a href="host-effects/CommitPlacement.html">
            
                    
                    commitPlacement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.2" data-path="host-effects/CommitWork.html">
            
                <a href="host-effects/CommitWork.html">
            
                    
                    commitWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.3" data-path="host-effects/CommitDeletion.html">
            
                <a href="host-effects/CommitDeletion.html">
            
                    
                    commitDeletion
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.5.5" data-path="commit-all-lifecycles.html">
            
                <a href="commit-all-lifecycles.html">
            
                    
                    commitAllLifecycle
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    功能
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../features/context.html">
            
                <a href="../features/context.html">
            
                    
                    context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../features/hydrate.html">
            
                <a href="../features/hydrate.html">
            
                    
                    hydrate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../features/ref.html">
            
                <a href="../features/ref.html">
            
                    
                    ref
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../features/event-injection.html">
            
                <a href="../features/event-injection.html">
            
                    
                    事件系统初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../features/event-bind.html">
            
                <a href="../features/event-bind.html">
            
                    
                    事件绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../features/event-dispatch.html">
            
                <a href="../features/event-dispatch.html">
            
                    
                    事件触发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../features/event-create-event-object.html">
            
                <a href="../features/event-create-event-object.html">
            
                    
                    事件对象生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../features/Suspense-component.html">
            
                <a href="../features/Suspense-component.html">
            
                    
                    Suspense
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../features/suspense.html">
            
                <a href="../features/suspense.html">
            
                    
                    挂起任务的含义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../features/suspense-lazy.html">
            
                <a href="../features/suspense-lazy.html">
            
                    
                    lazy 组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Hooks
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../hooks/hooks-start.html">
            
                <a href="../hooks/hooks-start.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../hooks/hooks-use-state.html">
            
                <a href="../hooks/hooks-use-state.html">
            
                    
                    useState
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../hooks/hooks-use-effect.html">
            
                <a href="../hooks/hooks-use-effect.html">
            
                    
                    useEffect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../hooks/hooks-others.html">
            
                <a href="../hooks/hooks-others.html">
            
                    
                    其他API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../hooks/hooks-common.html">
            
                <a href="../hooks/hooks-common.html">
            
                    
                    通用API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <form
            action="https://buttondown.email/api/emails/embed-subscribe/Jokcy"
            method="post"
            target="popupwindow"
            onsubmit="window.open('https://buttondown.email/Jokcy', 'popupwindow')"
            class="buttondown-form"
            >
            <input type="email" name="email" id="bd-email" placeholder="(your@email.com)">
            <input type="hidden" value="1" name="embed"/>
            <button type="submit">订阅我</button>
        </form>
    </li>
</ul>

                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                 
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >commitAllLifecycle</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div class="api-method"><div class="api-method-definition"><h1 id="commitalllifecycles">commitAllLifeCycles</h1><h3 id="commitupdatequeue">commitUpdateQueue</h3><p>&#x5BF9;&#x4E8E;<code>ClassComponent</code>&#xFF0C;&#x9700;&#x8981;&#x8C03;&#x7528;&#x751F;&#x547D;&#x5468;&#x671F;&#x65B9;&#x6CD5;&#x3002;&#x540C;&#x65F6;&#x5BF9;&#x4E8E;&#x521B;&#x5EFA;&#x4E86;&#x66F4;&#x65B0;&#x7684;<code>ClassComponent</code>&#xFF0C;&#x9700;&#x8981;&#x5224;&#x65AD;&#x8C03;&#x7528;&#x7684;<code>setState</code>&#x662F;&#x5426;&#x6709;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#x9700;&#x8981;&#x5728;&#x8FD9;&#x91CC;&#x4E00;&#x8D77;&#x8C03;&#x7528;&#x3002;&#x6CE8;&#x610F;&#x8FD9;&#x91CC;&#x628A;<code>capturedUpdates</code>&#x6302;&#x5230;&#x4E86;<code>updates</code>&#x4E0A;&#xFF0C;React &#x4F1A;&#x5C1D;&#x8BD5;&#x628A;&#x6355;&#x83B7;&#x4EA7;&#x751F;&#x7684;&#x66F4;&#x65B0;&#x653E;&#x5230;&#x4E0B;&#x4E00;&#x6B21;&#x6E32;&#x67D3;&#x4E0A;&#xFF08;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#xFF09;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;&#x672C;&#x8EAB;&#x5DF2;&#x7ECF;&#x6CA1;&#x6709;&#x66F4;&#x65B0;&#x4E86;&#xFF0C;&#x5219;&#x4F1A;&#x76F4;&#x63A5;&#x5220;&#x9664;&#x3002;</p><pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">commitUpdateQueue</span>&lt;<span class="hljs-title">State</span>&gt;(<span class="hljs-params">
  finishedWork: Fiber,
  finishedQueue: UpdateQueue&lt;State&gt;,
  instance: any,
  renderExpirationTime: ExpirationTime,
</span>): <span class="hljs-title">void</span> </span>{
  <span class="hljs-comment">// &#x5982;&#x679C;&#x6709;&#x4F4E;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x5219;&#x8BA9;&#x672C;&#x6B21;&#x6E32;&#x67D3;&#x6355;&#x83B7;&#x7684;&#x66F4;&#x65B0;&#x653E;&#x5230;&#x4F4E;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4EFB;&#x52A1;&#x4E0A;&#x6E32;&#x67D3;</span>
  <span class="hljs-comment">// &#x8FD9;&#x91CC;&#x7684;&#x5047;&#x8BBE;&#x662F;&#x5F53;&#x524D;&#x8282;&#x70B9;&#x4E0A;&#x4F4E;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4EFB;&#x52A1;&#x53EF;&#x80FD;&#x53EF;&#x4EE5;&#x5904;&#x7406;&#x6355;&#x83B7;&#x7684;&#x4EFB;&#x52A1;</span>
  <span class="hljs-comment">// &#x5982;&#x679C;&#x6CA1;&#x6709;&#x4F4E;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4EFB;&#x52A1;&#xFF0C;&#x5219;&#x6E05;&#x9664;&#x672C;&#x6B21;&#x6355;&#x83B7;&#x7684;&#x66F4;&#x65B0;</span>
  <span class="hljs-keyword">if</span> (finishedQueue.firstCapturedUpdate !== <span class="hljs-literal">null</span>) {
    <span class="hljs-comment">// Join the captured update list to the end of the normal list.</span>
    <span class="hljs-keyword">if</span> (finishedQueue.lastUpdate !== <span class="hljs-literal">null</span>) {
      finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate
      finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate
    }
    <span class="hljs-comment">// Clear the list of captured updates.</span>
    finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = <span class="hljs-literal">null</span>
  }

  <span class="hljs-comment">// Commit the effects</span>
  commitUpdateEffects(finishedQueue.firstEffect, instance)
  finishedQueue.firstEffect = finishedQueue.lastEffect = <span class="hljs-literal">null</span>

  commitUpdateEffects(finishedQueue.firstCapturedEffect, instance)
  finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = <span class="hljs-literal">null</span>
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">commitUpdateEffects</span>&lt;<span class="hljs-title">State</span>&gt;(<span class="hljs-params">
  effect: Update&lt;State&gt; | null,
  instance: any,
</span>): <span class="hljs-title">void</span> </span>{
  <span class="hljs-keyword">while</span> (effect !== <span class="hljs-literal">null</span>) {
    <span class="hljs-keyword">const</span> callback = effect.callback
    <span class="hljs-keyword">if</span> (callback !== <span class="hljs-literal">null</span>) {
      effect.callback = <span class="hljs-literal">null</span>
      callCallback(callback, instance)
    }
    effect = effect.nextEffect
  }
}</code></pre>
</div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">commitAllLifeCycles</span>(<span class="hljs-params">
  finishedRoot: FiberRoot,
  committedExpirationTime: ExpirationTime,
</span>) </span>{
  <span class="hljs-keyword">while</span> (nextEffect !== <span class="hljs-literal">null</span>) {
    <span class="hljs-keyword">const</span> effectTag = nextEffect.effectTag

    <span class="hljs-keyword">if</span> (effectTag &amp; (Update | Callback)) {
      recordEffect()
      <span class="hljs-keyword">const</span> current = nextEffect.alternate
      commitLifeCycles(
        finishedRoot,
        current,
        nextEffect,
        committedExpirationTime,
      )
    }

    <span class="hljs-keyword">if</span> (effectTag &amp; Ref) {
      recordEffect()
      commitAttachRef(nextEffect)
    }

    <span class="hljs-keyword">const</span> next = nextEffect.nextEffect
    nextEffect.nextEffect = <span class="hljs-literal">null</span>
    nextEffect = next
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">commitLifeCycles</span>(<span class="hljs-params">
  finishedRoot: FiberRoot,
  current: Fiber | null,
  finishedWork: Fiber,
  committedExpirationTime: ExpirationTime,
</span>): <span class="hljs-title">void</span> </span>{
  <span class="hljs-keyword">switch</span> (finishedWork.tag) {
    <span class="hljs-keyword">case</span> ClassComponent: {
      <span class="hljs-keyword">const</span> instance = finishedWork.stateNode
      <span class="hljs-keyword">if</span> (finishedWork.effectTag &amp; Update) {
        <span class="hljs-keyword">if</span> (current === <span class="hljs-literal">null</span>) {
          startPhaseTimer(finishedWork, <span class="hljs-string">&apos;componentDidMount&apos;</span>)
          instance.props = finishedWork.memoizedProps
          instance.state = finishedWork.memoizedState
          instance.componentDidMount()
          stopPhaseTimer()
        } <span class="hljs-keyword">else</span> {
          <span class="hljs-keyword">const</span> prevProps = current.memoizedProps
          <span class="hljs-keyword">const</span> prevState = current.memoizedState
          startPhaseTimer(finishedWork, <span class="hljs-string">&apos;componentDidUpdate&apos;</span>)
          instance.props = finishedWork.memoizedProps
          instance.state = finishedWork.memoizedState
          instance.componentDidUpdate(
            prevProps,
            prevState,
            instance.__reactInternalSnapshotBeforeUpdate,
          )
          stopPhaseTimer()
        }
      }
      <span class="hljs-keyword">const</span> updateQueue = finishedWork.updateQueue
      <span class="hljs-keyword">if</span> (updateQueue !== <span class="hljs-literal">null</span>) {
        instance.props = finishedWork.memoizedProps
        instance.state = finishedWork.memoizedState
        commitUpdateQueue(
          finishedWork,
          updateQueue,
          instance,
          committedExpirationTime,
        )
      }
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> HostRoot: {
      <span class="hljs-keyword">const</span> updateQueue = finishedWork.updateQueue
      <span class="hljs-keyword">if</span> (updateQueue !== <span class="hljs-literal">null</span>) {
        <span class="hljs-keyword">let</span> instance = <span class="hljs-literal">null</span>
        <span class="hljs-keyword">if</span> (finishedWork.child !== <span class="hljs-literal">null</span>) {
          <span class="hljs-keyword">switch</span> (finishedWork.child.tag) {
            <span class="hljs-keyword">case</span> HostComponent:
              instance = getPublicInstance(finishedWork.child.stateNode)
              <span class="hljs-keyword">break</span>
            <span class="hljs-keyword">case</span> ClassComponent:
              instance = finishedWork.child.stateNode
              <span class="hljs-keyword">break</span>
          }
        }
        commitUpdateQueue(
          finishedWork,
          updateQueue,
          instance,
          committedExpirationTime,
        )
      }
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> HostComponent: {
      <span class="hljs-keyword">const</span> instance: Instance = finishedWork.stateNode
      <span class="hljs-keyword">if</span> (current === <span class="hljs-literal">null</span> &amp;&amp; finishedWork.effectTag &amp; Update) {
        <span class="hljs-keyword">const</span> type = finishedWork.type
        <span class="hljs-keyword">const</span> props = finishedWork.memoizedProps
        commitMount(instance, type, props, finishedWork)
      }

      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> HostText: {
      <span class="hljs-comment">// We have no life-cycles associated with text.</span>
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> HostPortal: {
      <span class="hljs-comment">// We have no life-cycles associated with portals.</span>
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> Profiler: {
      <span class="hljs-keyword">if</span> (enableProfilerTimer) {
        <span class="hljs-keyword">const</span> onRender = finishedWork.memoizedProps.onRender

        <span class="hljs-keyword">if</span> (enableSchedulerTracing) {
          onRender(
            finishedWork.memoizedProps.id,
            current === <span class="hljs-literal">null</span> ? <span class="hljs-string">&apos;mount&apos;</span> : <span class="hljs-string">&apos;update&apos;</span>,
            finishedWork.actualDuration,
            finishedWork.treeBaseDuration,
            finishedWork.actualStartTime,
            getCommitTime(),
            finishedRoot.memoizedInteractions,
          )
        } <span class="hljs-keyword">else</span> {
          onRender(
            finishedWork.memoizedProps.id,
            current === <span class="hljs-literal">null</span> ? <span class="hljs-string">&apos;mount&apos;</span> : <span class="hljs-string">&apos;update&apos;</span>,
            finishedWork.actualDuration,
            finishedWork.treeBaseDuration,
            finishedWork.actualStartTime,
            getCommitTime(),
          )
        }
      }
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> SuspenseComponent: {
      <span class="hljs-keyword">if</span> (finishedWork.effectTag &amp; Callback) {
        <span class="hljs-keyword">const</span> newState: SuspenseState = {
          alreadyCaptured: <span class="hljs-literal">true</span>,
          didTimeout: <span class="hljs-literal">false</span>,
          timedOutAt: NoWork,
        }
        finishedWork.memoizedState = newState
        scheduleWork(finishedWork, Sync)
        <span class="hljs-keyword">return</span>
      }
      <span class="hljs-keyword">let</span> oldState: SuspenseState | <span class="hljs-literal">null</span> =
        current !== <span class="hljs-literal">null</span> ? current.memoizedState : <span class="hljs-literal">null</span>
      <span class="hljs-keyword">let</span> newState: SuspenseState | <span class="hljs-literal">null</span> = finishedWork.memoizedState
      <span class="hljs-keyword">let</span> oldDidTimeout = oldState !== <span class="hljs-literal">null</span> ? oldState.didTimeout : <span class="hljs-literal">false</span>

      <span class="hljs-keyword">let</span> newDidTimeout
      <span class="hljs-keyword">let</span> primaryChildParent = finishedWork
      <span class="hljs-keyword">if</span> (newState === <span class="hljs-literal">null</span>) {
        newDidTimeout = <span class="hljs-literal">false</span>
      } <span class="hljs-keyword">else</span> {
        newDidTimeout = newState.didTimeout
        <span class="hljs-keyword">if</span> (newDidTimeout) {
          primaryChildParent = finishedWork.child
          newState.alreadyCaptured = <span class="hljs-literal">false</span>
          <span class="hljs-keyword">if</span> (newState.timedOutAt === NoWork) {
            newState.timedOutAt = requestCurrentTime()
          }
        }
      }

      <span class="hljs-keyword">if</span> (newDidTimeout !== oldDidTimeout &amp;&amp; primaryChildParent !== <span class="hljs-literal">null</span>) {
        hideOrUnhideAllChildren(primaryChildParent, newDidTimeout)
      }
      <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">case</span> IncompleteClassComponent:
      <span class="hljs-keyword">break</span>
    <span class="hljs-keyword">default</span>: {
      invariant(
        <span class="hljs-literal">false</span>,
        <span class="hljs-string">&apos;This unit of work tag should not have side-effects. This error is &apos;</span> +
          <span class="hljs-string">&apos;likely caused by a bug in React. Please file an issue.&apos;</span>,
      )
    }
  }
}</code></pre>
</div></div></div>




                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
<div id="disqus_thread"></div>
<script>
  /**
   *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
   *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
  /*
var disqus_config = function () {
this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
  ;(function() {
    // DON'T EDIT BELOW THIS LINE
    var d = document,
      s = d.createElement('script')
    s.src = 'https://react-source-code.disqus.com/embed.js'
    s.setAttribute('data-timestamp', +new Date())
    ;(d.head || d.body).appendChild(s)
  })()
</script>
<noscript
  >Please enable JavaScript to view the
  <a href="https://disqus.com/?ref_noscript"
    >comments powered by Disqus.</a
  ></noscript
>

            </div>

            

        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"commitAllLifecycle","level":"1.5.5","depth":2,"next":{"title":"功能","level":"1.6","depth":1,"ref":"","articles":[{"title":"context","level":"1.6.1","depth":2,"path":"book/features/context.md","ref":"book/features/context.md","articles":[]},{"title":"hydrate","level":"1.6.2","depth":2,"path":"book/features/hydrate.md","ref":"book/features/hydrate.md","articles":[]},{"title":"ref","level":"1.6.3","depth":2,"path":"book/features/ref.md","ref":"book/features/ref.md","articles":[]},{"title":"事件系统初始化","level":"1.6.4","depth":2,"path":"book/features/event-injection.md","ref":"book/features/event-injection.md","articles":[]},{"title":"事件绑定","level":"1.6.5","depth":2,"path":"book/features/event-bind.md","ref":"book/features/event-bind.md","articles":[]},{"title":"事件触发","level":"1.6.6","depth":2,"path":"book/features/event-dispatch.md","ref":"book/features/event-dispatch.md","articles":[]},{"title":"事件对象生成","level":"1.6.7","depth":2,"path":"book/features/event-create-event-object.md","ref":"book/features/event-create-event-object.md","articles":[]},{"title":"Suspense","level":"1.6.8","depth":2,"path":"book/features/Suspense-component.md","ref":"book/features/Suspense-component.md","articles":[]},{"title":"挂起任务的含义","level":"1.6.9","depth":2,"path":"book/features/suspense.md","ref":"book/features/suspense.md","articles":[]},{"title":"lazy 组件","level":"1.6.10","depth":2,"path":"book/features/suspense-lazy.md","ref":"book/features/suspense-lazy.md","articles":[]}]},"previous":{"title":"commitDeletion","level":"1.5.4.3","depth":3,"path":"book/commit-phase/host-effects/CommitDeletion.md","ref":"book/commit-phase/host-effects/CommitDeletion.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-api"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["weibo","google","twitter","weibo","instapaper"]},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-api":{"languages":[],"split":true,"theme":"light"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"React源码解析","language":"zh-hans","gitbook":"*"},"file":{"path":"book/commit-phase/commit-all-lifecycles.md","mtime":"2019-01-07T03:56:29.819Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2019-07-08T12:28:32.264Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-api/theme-api.js"></script>
        
    

    </body>
</html>

